How V8 decides what memory to reclaim, and when.
JavaScript manages memory automatically, and the core question the garbage collector answers is reachability, not lifetime: an object is kept alive as long as something can still reach it, starting from root references (global variables, the current call stack) and following every reference outward. Anything unreachable from those roots is garbage, regardless of how recently it was created or used.
V8's collector isn't one algorithm — it splits the heap into a young generation (most objects die young, so this is collected frequently with a fast copying algorithm called Scavenger) and an old generation (long-lived objects, collected less often using mark-sweep-compact). Much of this work happens incrementally or concurrently with your code running, specifically to avoid long 'stop-the-world' pauses that would freeze the page. Memory leaks in JS almost always come down to something unintentionally staying reachable — forgotten timers, detached DOM nodes still referenced from JS, or closures holding onto more scope than they need.
What you'll walk away knowing